package main.cn.dao.impl;

import main.cn.dao.StaffDao;
import main.cn.pojo.Staff;

import java.util.List;


public class StaffDaoImpl extends BaseDao implements StaffDao {
    @Override
    public int addStaff(Staff staff) {
        String sql = "insert into employees (id,name,sex,telephone,email,address) values(?,?,?,?,?,?)";
        return update(sql,staff.getId(),staff.getName(),staff.getSex(),staff.getTelephone(),staff.getEmail(),staff.getAddress());
    }

    @Override
    public int deleteStaff(int sid) {
        String sql = "delete from employees where id = ?";
        return update(sql,sid);
    }

    @Override
    public int updateStaff(Staff staff) {
        String sql = "update employees set name=?,sex=?,telephone=?,email=?,address=? where id = ?";
        return update(sql,staff.getName(),staff.getSex(),staff.getTelephone(),staff.getEmail(),staff.getAddress(),staff.getId());
    }

    @Override
    public Staff queryStaffById(int sid) {
        String sql = "select id, name, sex, telephone, email, address from employees where id = ?";
        return queryForOne(Staff.class,sql,sid);
    }

    @Override
    public List<Staff> queryStaffs() {
        String sql = "select id, name, sex, telephone, email, address from employees";
        System.out.println("查询sql语句");
        return queryForList(Staff.class,sql);
    }
}
